package com.leyou.page.listener;


import com.leyou.common.constant.MQConstants;
import com.leyou.page.service.PageService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PageListener {
    @Autowired
    private PageService pageService;
   /* @Autowired
    PageService pageService;
    //商品上架，添加一个静态页
    @RabbitListener(bindings =@QueueBinding
            (value = @Queue(value =MQConstants.Queue.PAGE_ITEM_UP,durable = "true"),//指定当前监听的队列
            exchange = @Exchange(value =MQConstants.Exchange.ITEM_EXCHANGE_NAME, type = ExchangeTypes.TOPIC),//指定当前队列绑定的交换机
                    key = MQConstants.RoutingKey.ITEM_UP_KEY //队列绑定的routingKey
    ))
    public void addStaticPage(Long id){
        pageService.buildStaticPage(id);
    }

    *//**
     * 商品下架，删除一个静态页
     *//*
    @RabbitListener(bindings =@QueueBinding
            (value = @Queue(value =MQConstants.Queue.PAGE_ITEM_DOWN,durable = "true"),//指定当前监听的队列
                    exchange = @Exchange(value =MQConstants.Exchange.ITEM_EXCHANGE_NAME, type = ExchangeTypes.TOPIC),//指定当前队列绑定的交换机
                    key = MQConstants.RoutingKey.ITEM_DOWN_KEY //队列绑定的routingKey
            ))
    public void delStaticPage(Long id){
        pageService.delStaticPage(id);
    }
*/
    /**
     * 商品上架，添加一个静态页
     */
    @RabbitListener(bindings=@QueueBinding(
            value = @Queue(value = MQConstants.Queue.PAGE_ITEM_UP, durable="true"),//指定当前监听的队列
            exchange = @Exchange(value = MQConstants.Exchange.ITEM_EXCHANGE_NAME, type= ExchangeTypes.TOPIC),//指定当前队列绑定的交换机
            key = MQConstants.RoutingKey.ITEM_UP_KEY//队列绑定的routingKey
    ))
    public void addStaticPage(Long id){
        pageService.buildStaticPage(id);
    }

    /**
     * 商品下架，删除一个静态页
     */
    @RabbitListener(bindings=@QueueBinding(
            value = @Queue(value = MQConstants.Queue.PAGE_ITEM_DOWN, durable="true"),//指定当前监听的队列
            exchange = @Exchange(value = MQConstants.Exchange.ITEM_EXCHANGE_NAME, type= ExchangeTypes.TOPIC),//指定当前队列绑定的交换机
            key = MQConstants.RoutingKey.ITEM_DOWN_KEY//队列绑定的routingKey
    ))
    public void delStaticPage(Long id){
        pageService.delStaticPage(id);
    }


}
